import 'package:changxindianzishangwu/dao/collect_dao.dart';
import 'package:changxindianzishangwu/model/collect_list_model.dart';
import 'package:changxindianzishangwu/util/app_color.dart';
import 'package:changxindianzishangwu/util/colors.dart';
import 'package:changxindianzishangwu/util/event_bus.dart';
import 'package:changxindianzishangwu/util/toast.dart';
import 'package:changxindianzishangwu/widget/app_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

///收藏=》备注
class CollectNotePage extends StatefulWidget {
  CollectBean bean;

  CollectNotePage(this.bean, {Key key}) : super(key: key);

  @override
  _CollectNotePageState createState() => _CollectNotePageState();
}

class _CollectNotePageState extends State<CollectNotePage> {
  TextEditingController _controller;

  @override
  void initState() {
    _controller = TextEditingController(text:"${widget.bean.remarks == "-1" ? "" : widget.bean.remarks}");
    super.initState();
  }
  @override
  void dispose() {
    // TODO: implement dispose
    EasyLoading.dismiss();
    super.dispose();
  }
  void updateNote() async{
    String _remarks= _controller.text.toString().trim();
    CollectListModel _model =
    await CollectDao.collectUpdateNote(widget.bean.emojiId,_remarks);
    EasyLoading.dismiss();  
    if(_model.resultCode==0){
      toast("修改备注失败");
      return;
    }
    toast("修改成功");
    Get.back(result: _remarks);

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TopAppBar(
        context,
        "添加备注",
        rightText: "完成",
        isRightTextBtn: true,
        rightCallback: () {
          EasyLoading.show(status: "正在修改...");
          updateNote();

        },
      ),
      body: Container(
        color: Colors.white,
        height: double.infinity,
        child: Column(children: [
          Container(
            margin: EdgeInsets.only(
                left: width(15), right: width(15), top: height(10)),
            child: TextField(
              maxLength: 24,
              controller: _controller,
              maxLines: 1,
              cursorColor: AppColor.colorTheme,
              keyboardType: TextInputType.text,
              style: TextStyle(color: AppColor.colorText85, fontSize: 15),
              decoration: InputDecoration(
                  fillColor: AppColor.bg,
                  filled: true,
                  counterText: "24个字符以内",
                  contentPadding:EdgeInsets.only(left: 15,right: 15),
                  hintText: "请输入备注...",
                  hintStyle:
                      TextStyle(color: AppColor.colorHintText, fontSize: 15),
                  enabledBorder: OutlineInputBorder(

                      borderSide: BorderSide(color: Color(0x00FF0000)),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  border: OutlineInputBorder(
                      borderSide: BorderSide(color: Color(0x00000000)),
                      borderRadius: BorderRadius.all(Radius.circular(5)))),
            ),
          ),
        ]),
      ),
    );
  }
}

